<ResourceDictionary 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >

<Style x:Key="{x:Type Menu}" TargetType="{x:Type Menu}">
    <Setter Property="OverridesDefaultStyle" Value="True"/>
    <Setter Property="SnapsToDevicePixels" Value="True"/>
    <Setter Property="Foreground" Value="{StaticResource NormalForeground}"/>
    <Setter Property="Height" Value="25"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Menu}">
          <Border
            Background="{StaticResource LightBrush}"
            BorderBrush="{StaticResource NormalBorderBrush}"
            BorderThickness="1">
            <StackPanel ClipToBounds="True" Orientation="Horizontal" IsItemsHost="True" CanVerticallyScroll="True" MaxHeight="500" />
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
    <Style TargetType="{x:Type MenuItem}">
        <Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
        <Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Foreground" Value="{StaticResource OutsideFontColor}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type MenuItem}">
                    <ControlTemplate.Resources>
                        <Storyboard x:Key="HighlightOn">
                            <DoubleAnimation Duration="00:00:00.1000000" Storyboard.TargetName="BackgroundGradientSelected" Storyboard.TargetProperty="Opacity" To="0.84"/>
                        </Storyboard>
                        <Storyboard x:Key="HighlightOff">
                            <DoubleAnimation Duration="00:00:00.4000000" Storyboard.TargetName="BackgroundGradientSelected" Storyboard.TargetProperty="Opacity" To="0"/>
                        </Storyboard>
                    </ControlTemplate.Resources>
                    <Border x:Name="Border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                        <Grid Margin="1,1,1,1">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition MinWidth="17" Width="Auto" SharedSizeGroup="MenuItemIconColumnGroup"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto" SharedSizeGroup="MenuItemIGTColumnGroup"/>
                                <ColumnDefinition Width="14"/>
                            </Grid.ColumnDefinitions>
                            <Rectangle x:Name="BackgroundGradientOver" Fill="{StaticResource hoverGradient}" Stroke="{StaticResource hoverStroke}" RadiusX="2" RadiusY="2"  Opacity="0" Grid.ColumnSpan="4"/>
                            <Rectangle x:Name="BackgroundGradientSelected" Fill="{StaticResource BtnOverFill}" Stroke="{StaticResource selectedStroke}" RadiusX="2" RadiusY="2" Opacity="0" Grid.ColumnSpan="4"/>
                            <Rectangle x:Name="BackgroundHighlight" Margin="1" Stroke="#A0FFFFFF" RadiusX="1" RadiusY="1" Grid.ColumnSpan="4" Opacity="0"/>
                            
                            <ContentPresenter Margin="4,0,6,0" x:Name="Icon" VerticalAlignment="Center" ContentSource="Icon" MinWidth="16"/>
                            <Grid Visibility="Hidden" Margin="4,0,6,0" x:Name="GlyphPanel" VerticalAlignment="Center">
                                <Path x:Name="GlyphPanelpath" VerticalAlignment="Center" Fill="{TemplateBinding Foreground}" Data="M0,2 L0,4.8 L2.5,7.4 L7.1,2.8 L7.1,0 L2.5,4.6 z" FlowDirection="LeftToRight"/>
                            </Grid>

                            <ContentPresenter Grid.Column="1" Margin="{TemplateBinding Padding}" x:Name="HeaderHost" RecognizesAccessKey="True" ContentSource="Header"/>

                            <Grid Grid.Column="3" Margin="4,0,6,0" x:Name="ArrowPanel" VerticalAlignment="Center">
                                <Path x:Name="ArrowPanelPath" VerticalAlignment="Center" Fill="{TemplateBinding Foreground}" Data="M0,0 L0,8 L4,4 z"/>
                            </Grid>

                            <Popup IsOpen="{Binding Path=IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" Placement="Right" x:Name="SubMenuPopup" Focusable="false" AllowsTransparency="true" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" VerticalOffset="-3">
                                <Grid x:Name="SubMenu">
                                    <Border x:Name="SubMenuBorder"  Background="#FFFFFFFF" BorderBrush="{StaticResource TextBoxNorm}" BorderThickness="1"/>
                                    <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle"/>
                                </Grid>
                            </Popup>

                        </Grid>
                    </Border>

                    <ControlTemplate.Triggers>

                        <Trigger Property="Role" Value="TopLevelHeader">
                            <Setter Property="Padding" Value="0"/>
                            <Setter Property="Grid.IsSharedSizeScope" Value="true"/>
                            <Setter Property="Visibility" Value="Collapsed" TargetName="Icon"/>
                            <Setter Property="Visibility" Value="Collapsed" TargetName="GlyphPanel"/>
                            <Setter Property="Placement" Value="Bottom" TargetName="SubMenuPopup"/>
                            <Setter Property="Visibility" Value="Collapsed" TargetName="ArrowPanel"/>
                        </Trigger>

                        <Trigger Property="Role" Value="TopLevelItem">
                            <Setter Property="Padding" Value="1,0,1,0"/>
                            <Setter Property="Visibility" Value="Collapsed" TargetName="ArrowPanel"/>
                        </Trigger>

                        <Trigger Property="Role" Value="SubmenuHeader">
                            <Setter Property="DockPanel.Dock" Value="Top"/>
                            <Setter Property="Padding" Value="11,2,0,2"/>
                            <Setter Property="Grid.IsSharedSizeScope" Value="true"/>
                        </Trigger>

                        <Trigger Property="Role" Value="SubmenuItem">
                            <Setter Property="DockPanel.Dock" Value="Top"/>
                            <Setter Property="Padding" Value="11,2,0,2"/>
                            <Setter Property="Visibility" Value="Collapsed" TargetName="ArrowPanel"/>
                        </Trigger>
                        <Trigger Property="IsSuspendingPopupAnimation" Value="true">
                            <Setter Property="PopupAnimation" Value="None" TargetName="SubMenuPopup"/>
                        </Trigger>

                        <!--Trigger Property="Icon" Value="{x:Null}">
                            <Setter Property="Visibility" Value="Collapsed" TargetName="Icon"/>
                        </Trigger-->

                        <Trigger Property="IsChecked" Value="true">
                            <Setter Property="Visibility" Value="Visible" TargetName="GlyphPanel"/>
                            <Setter Property="Visibility" Value="Collapsed" TargetName="Icon"/>
                        </Trigger>

                        <Trigger Property="AllowsTransparency" SourceName="SubMenuPopup" Value="true">
                            <Setter Property="Margin" Value="0,0,3,3" TargetName="SubMenu"/>
                            <Setter Property="SnapsToDevicePixels" Value="true" TargetName="SubMenu"/>
                            <Setter Property="BitmapEffect" Value="{DynamicResource PopupDropShadow}" TargetName="SubMenuBorder"/>
                        </Trigger>

                        <Trigger Property="IsHighlighted" Value="true">
                            <Trigger.ExitActions>
                                <BeginStoryboard Storyboard="{StaticResource HighlightOff}" />
                            </Trigger.ExitActions>
                            <Trigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource HighlightOn}" />
                            </Trigger.EnterActions>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
  <!--Style x:Key="{x:Type MenuItem}" TargetType="{x:Type MenuItem}">
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type MenuItem}">
          <Border x:Name="Border"
                  Background="{StaticResource LightBrush}"
                  BorderBrush="{StaticResource NormalBorderBrush}"
                  BorderThickness="1">
            <Grid>
              <Grid.ColumnDefinitions>
                <ColumnDefinition x:Name="Col0" MinWidth="17" Width="Auto" SharedSizeGroup="MenuItemIconColumnGroup"/>
                <ColumnDefinition Width="Auto" SharedSizeGroup="MenuTextColumnGroup"/>
                <ColumnDefinition Width="Auto" SharedSizeGroup="MenuItemIGTColumnGroup"/>
                <ColumnDefinition x:Name="Col3" Width="14"/>
              </Grid.ColumnDefinitions>

              <!- ContentPresenter to show an Icon if needed ->
              <ContentPresenter Grid.Column="0" Margin="4,0,6,0" x:Name="Icon" VerticalAlignment="Center" ContentSource="Icon"/>

              <!- Glyph is a checkmark if needed for a checkable menu ->
              <Grid Grid.Column="0" Visibility="Hidden" Margin="4,0,6,0" x:Name="GlyphPanel" VerticalAlignment="Center">
                <Path x:Name="GlyphPanelpath" VerticalAlignment="Center" Fill="{StaticResource GlyphBrush}" Data="M0,2 L0,4.8 L2.5,7.4 L7.1,2.8 L7.1,0 L2.5,4.6 z" FlowDirection="LeftToRight"/>
              </Grid>

              <!- Content for the menu text etc ->
              <ContentPresenter Grid.Column="1"
                                Margin="{TemplateBinding Padding}"
                                x:Name="HeaderHost"
                                RecognizesAccessKey="True"
                                ContentSource="Header"/>

              <!- Content for the menu IGT ->
              <ContentPresenter Grid.Column="2"
                                Margin="8,1,8,1"
                                x:Name="IGTHost"
                                ContentSource="InputGestureText"
                                VerticalAlignment="Center"/>

              <!- Arrow drawn path which points to the next level of the menu ->
              <Grid Grid.Column="3" Margin="4,0,6,0" x:Name="ArrowPanel" VerticalAlignment="Center">
                <Path x:Name="ArrowPanelPath" HorizontalAlignment="Right" VerticalAlignment="Center" Fill="{StaticResource GlyphBrush}" Data="M0,0 L0,8 L4,4 z"/>
              </Grid>

              <!- The Popup is the body of the menu which expands down or across depending on the level of the item ->
              <Popup IsOpen="{Binding Path=IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" Placement="Right" x:Name="SubMenuPopup" Focusable="false" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}">
                <Border x:Name="SubMenuBorder" BorderBrush="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}}" BorderThickness="1" Padding="0">
                  <Grid x:Name="SubMenu" Grid.IsSharedSizeScope="True">
                    <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" MaxHeight="500">
                      <!- StackPanel holds children of the menu. This is set by IsItemsHost=True->
                      <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle"  />
                    </ScrollViewer>
                  </Grid>
                </Border>
              </Popup>
            </Grid>
          </Border>

          <!- These triggers re-configure the four arrangements of MenuItem to show different levels of menu via Role ->
          <ControlTemplate.Triggers>
            <!- Role = TopLevelHeader : this is the root menu item in a menu; the Popup expands down ->
            <Trigger Property="Role" Value="TopLevelHeader">
              <Setter Property="Padding" Value="6,1,6,1"/>
              <Setter Property="Placement" Value="Bottom" TargetName="SubMenuPopup"/>
              <Setter Property="MinWidth" Value="0" TargetName="Col0"/>
              <Setter Property="Width" Value="Auto" TargetName="Col3"/>
              <Setter Property="Visibility" Value="Collapsed" TargetName="Icon"/>
              <Setter Property="Visibility" Value="Collapsed" TargetName="GlyphPanel"/>
              <Setter Property="Visibility" Value="Collapsed" TargetName="IGTHost"/>
              <Setter Property="Visibility" Value="Collapsed" TargetName="ArrowPanel"/>
              <Setter Property="BorderBrush" Value="Transparent" TargetName="Border"/>
            </Trigger>

            <!- Role = TopLevelItem :  this is a child menu item from the top level without any child items->
            <Trigger Property="Role" Value="TopLevelItem">
              <Setter Property="Padding" Value="6,1,6,1"/>
              <Setter Property="Visibility" Value="Collapsed" TargetName="ArrowPanel"/>
            </Trigger>

            <!- Role = SubMenuHeader : this is a child menu item which does not have children ->
            <Trigger Property="Role" Value="SubmenuHeader">
              <Setter Property="DockPanel.Dock" Value="Top"/>
              <Setter Property="Padding" Value="0,2,0,2"/>
              <Setter Property="BorderBrush" Value="{StaticResource WindowBackgroundBrush}" TargetName="Border"/>
              <Setter Property="Background" Value="{StaticResource WindowBackgroundBrush}" TargetName="Border"/>
            </Trigger>

            <!- Role = SubMenuItem : this is a child menu item which has children->
            <Trigger Property="Role" Value="SubmenuItem">
              <Setter Property="DockPanel.Dock" Value="Top"/>
              <Setter Property="Padding" Value="0,2,0,2"/>
              <Setter Property="Visibility" Value="Collapsed" TargetName="ArrowPanel"/>
              <Setter Property="BorderBrush" Value="{StaticResource WindowBackgroundBrush}" TargetName="Border"/>
              <Setter Property="Background" Value="{StaticResource WindowBackgroundBrush}" TargetName="Border"/>
            </Trigger>
            <Trigger Property="IsSuspendingPopupAnimation" Value="true">
              <Setter Property="PopupAnimation" Value="None" TargetName="SubMenuPopup"/>
            </Trigger>

            <!- If no Icon is present the we collapse the Icon Content ->
            <Trigger Property="Icon" Value="{x:Null}">
              <Setter Property="Visibility" Value="Collapsed" TargetName="Icon"/>
            </Trigger>

            <!- The GlyphPanel contains the CheckMark ->
            <Trigger Property="IsChecked" Value="true">
              <Setter Property="Visibility" Value="Visible" TargetName="GlyphPanel"/>
              <Setter Property="Visibility" Value="Collapsed" TargetName="Icon"/>
            </Trigger>

            <!- Using the system colors for the Menu Highlight and IsEnabled->
            <Trigger Property="IsHighlighted" Value="true">
              <Setter Property="Background" Value="{StaticResource SelectedBackgroundBrush}" TargetName="Border"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
              <Setter Property="Foreground" Value="LightGray"/>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style-->
</ResourceDictionary>